package com.ly.algorithm.DataStructures.sort;
import java.util.Date;
import	java.util.Random;

/**
 * @Classname BubbleSort
 * @Description TODO
 * @Date 2020/4/24 9:50
 * @Author 冷心影翼
 */
public class BubbleSort {
    public static void main(String[] args) {
//        int[] arr = {3,202,-21,23,34,34,56,7,13,23,77};
        int[] arr = new int[80000];

        Random random = new Random();
        for(int i=0;i<80000;i++) {
            arr[i] =  random.nextInt(80000);
        }

        Date date1 = new Date();
        Long count = 0L;
        for(int i=0;i<arr.length-1;i++) {
            int flag = 0;
            for(int j=0;j<arr.length-1-i;j++) {
                if(arr[j]>arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = 1;

                }
                count++;
            }
            if(flag == 0) {
                break;
            }
        }
        Date date2 = new Date();

        System.out.println("花费时间"+(date2.getTime()-date1.getTime())+" ms");
        System.out.println(date1);
        System.out.println(date2);
        for(int i=0;i<arr.length;i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println("比较次数"+count);
    }
}
